﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class Activity
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            pg.Type = "Activity";
            pg.Title = "";
            pg.AddText = "新增";
            pg.EditText = "";
            pg.LocateText = "查询";
            pg.SMenuId = "HD";
            pg.FileUrl = "../Activitys/Activity";
            pg.Condition = "";
            pg.TableName = "cu_Activity";
            pg.KeyFieldName = "id";
            pg.PopEditHeight = 550;
            pg.PopEditWidth = 760;
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            pg.Sop.DEL = false;
            pg.Sop.EDIT_htm = " ";
            DataRow drUser = BasePage.GetUser(session);
            String leagueId = Fun.cString(drUser["LeagueId"].ToString());
            //pg.Tab.Add("课程", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=BaseCourse';GoPage(1);");
            //pg.Tab.Add("套餐", "LocatePara='';DataPageUrl='../Main/DataPageLay?type=MealCourse';GoPage(1);");
            string Url = "../Activitys/Activity/UpdateState";//convert(varchar(10), cu_Account.id)
            string DelUrl = "../Activitys/Activity/DelActivity";
            string Downl = "../Activitys/Activity/Downline";
            string Used = "../Activitys/Activity/Used";

            pg.Sql = @"select id,ActivityName,CreateDate,Classhour,NoMPrice,MPrice,Remark,ImageUrl,ImageName,used,convert(varchar(100),Actend,111) as Actend,convert(varchar(100),Actstart,111)as Actstart,convert(varchar(100),EndSign,111)as EndSign,
case  when (MonthStart > '0') then convert(varchar,(MonthStart/12))+'年'+convert(varchar,(MonthStart%12))+'月-'+convert(varchar,(MonthEnd/12))+'年'+convert(varchar,(MonthEnd%12))+'月'  END as Month ,
case ActType when 0 then '<span style=''color:green''>免费</span>' when 1 then '<span style=''color:red''>收费</span>' END as ActType ,
case state when 0 then '<span style=''color:#aaa''>下线</span>' when 1 then '上线' END as state ,
case SignNumber when 0 then  CONVERT(varchar,isnull(a.num,0))+'/无限制'
ELSE convert(varchar,isnull(a.num,0))+'/'+convert(varchar,SignNumber)  END as SignNumber ,
convert(varchar(100),Actstart,23)+'~'+ convert(varchar(100),Actend,23) as ActivityTime ,
CASE used when 1 then
'<a class=''layui-btn layui-bg-blue layui-btn-xs''  href=""javascript:ShowModalUrl(''popEdit'', ''../Activitys/ActivitySp?id='+ltrim(id)+'&keyCode=''+GetKeyCode('+ltrim(id)+'), '''', '''', 1400, 700)"">学员签到</a>'+
CASE isnull(a.num,0) when 0 then 
case state when 0 then
'<a class=''layui-btn layui-bg-green layui-btn-xs'' href=""javascript: Do(''" + Downl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+'''),type:1})"" >上线</a>'
when 1 then
'<a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Downl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+'''),type:0})"" >下线</a>'
END+
'<a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + DelUrl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+''')})"" >删除</a>'
else
case state when 0 then
'<a class=''layui-btn layui-bg-green layui-btn-xs'' href=""javascript: Do(''" + Downl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+'''),type:1})"" >上线</a>'
when 1 then
'<a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Downl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+'''),type:0})"" >下线</a>'
END
END 
else 
'<a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Used + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+'''),type:0})"" >审核</a>'
END
as link 
from  cu_Activity
left join
(select COUNT(*) num,ActivityId from cu_Activity_SignUp  group by ActivityId ) a on a.ActivityId= cu_Activity.id
where LeagueId=" + leagueId;
            //  pg.Sql = "select * from cu_Account where LeagueId = 1"; cl.DictTypeID = "D18";
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.FieldName = "ActivityName"; cl.HeadText = "名称"; cl.Visible = true; cl.IsCondition = true; cl.ConditionPosition = 1; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "state"; cl.HeadText = "状态"; cl.Visible = true; cl.IsCondition = true; cl.ConditionPosition = 1; cl.DictTypeID = "D19"; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "SignNumber"; cl.HeadText = "报名人数"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);//报名人数0是不限的意思，已报名人数根据报名表的数量来
            cl = new ColumnInfo(); cl.FieldName = "Month"; cl.HeadText = "年龄段"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "ActivityTime"; cl.DataType = Tag.DateTime; cl.HeadText = "活动时间"; cl.Visible = true; cl.Width = 160; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "ActType"; cl.HeadText = "性质"; cl.Visible = true; cl.IsCondition = true; cl.ConditionPosition = 1; cl.DictTypeID = "D20"; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Remark"; cl.HeadText = "备注"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.DateTime; cl.FieldName = "CreateDate"; cl.DataType = Tag.DateTime; cl.HeadText = "创建时间"; cl.Visible = true; cl.DisplayFormat = "{0:dd / MM / yyyy}"; cl.IsCondition = true; cl.ConditionPosition = 1; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; pg.AddColumn(cl);
            return pg;
        }

    }
}